<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/admin/include/init_admin.jsp" %>
<%@ page import="com.joinhawaii.admin.sales.*" %>
<%


	String job_type		= "U";
	String req_id		= StringUtil.nvl(request.getParameter("req_id"));
	String est_no		= StringUtil.nvl(request.getParameter("est_no"));
	String est_type		= "2";


	if (est_no.equals("")) {
		job_type = "C";
	}


	HashMap infos = new HashMap();
	infos.put("est_no",	est_no);
	infos.put("req_id", req_id);
	infos.put("est_type", est_type);			//1:견적서, 2:예약확인서

	SalesDAO dao 			= new SalesDAO();


	HashList list 			= dao.selectReqList(infos);			//견적의뢰
	HashList estList 		= dao.selectConfirmList(infos);		//예약확인서,바우처,안내문 목록




	String s_req_dt			= StringUtil.nvl(request.getParameter("s_req_dt"));
	String s_start_dt_from	= StringUtil.nvl(request.getParameter("s_start_dt_from"));
	String s_start_dt_to	= StringUtil.nvl(request.getParameter("s_start_dt_to"));
	String s_req_status		= StringUtil.nvl(request.getParameter("s_req_status"));
	String s_customer_name	= StringUtil.toHan(request.getParameter("s_customer_name"));
	String s_email_addr		= StringUtil.toHan(request.getParameter("s_email_addr"));
	String s_phone_no		= StringUtil.nvl(request.getParameter("s_phone_no"));
	String s_hotel_name		= StringUtil.nvl(request.getParameter("s_hotel_name"));
	String s_enjoy_name		= StringUtil.nvl(request.getParameter("s_enjoy_name"));
	String s_car_company	= StringUtil.nvl(request.getParameter("s_car_company"));

	String s_hotel_chk		= StringUtil.nvl(request.getParameter("s_hotel_chk"));
	String s_enjoy_chk		= StringUtil.nvl(request.getParameter("s_enjoy_chk"));
	String s_car_chk		= StringUtil.nvl(request.getParameter("s_car_chk"));

	String s_curr_page		= StringUtil.nvl(request.getParameter("s_curr_page"),"1");



	String where = "?1=1";
	if (!"".equals(s_req_dt))			where += "&s_req_dt=" + s_req_dt;
	if (!"".equals(s_start_dt_from))	where += "&s_start_dt_from=" + s_start_dt_from;
	if (!"".equals(s_start_dt_to))		where += "&s_start_dt_to=" + s_start_dt_to;
	if (!"".equals(s_req_status))		where += "&s_req_status=" + s_req_status;
	if (!"".equals(s_customer_name))	where += "&s_customer_name=" + s_customer_name;
	if (!"".equals(s_email_addr))		where += "&s_email_addr=" + s_email_addr;
	if (!"".equals(s_phone_no))			where += "&s_phone_no=" + s_phone_no;
	if (!"".equals(s_hotel_name))		where += "&s_hotel_name=" + s_hotel_name;
	if (!"".equals(s_enjoy_name))		where += "&s_enjoy_name=" + s_enjoy_name;
	if (!"".equals(s_car_company))		where += "&s_car_company=" + s_car_company;
	if (!"".equals(s_hotel_chk))		where += "&s_hotel_chk=" + s_hotel_chk;
	if (!"".equals(s_enjoy_chk))		where += "&s_enjoy_chk=" + s_enjoy_chk;
	if (!"".equals(s_car_chk))			where += "&s_car_chk=" + s_car_chk;

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>조인하와이</title>
	<%@ include file="/admin/include/cssnjs.jsp"  %>

	<script type="text/javascript">

	$(document).ready(function() {

		$('input, select').live("keypress", function(e) {
            /* ENTER PRESSED*/
            if (e.keyCode == 13) {
                /* FOCUS ELEMENT */
                var inputs = $(this).parents("form").eq(0).find("input, select");
                var idx = inputs.index(this);

                if (idx == inputs.length - 1) {
                    //inputs[0].select()
                } else {
                    inputs[idx + 1].focus(); //  handles submit buttons
                    //inputs[idx + 1].select();
                }
                return false;
            }
        });

		$('input[type="checkbox"]').click(function() {
			if ($(this).attr('checked') == 'checked') {
				$(this).closest('tr').find('input[name="est.chk"]').val('Y');
			} else {
				$(this).closest('tr').find('input[name="est.chk"]').val('X');
			}
		});


	<%	if (!"".equals(est_no)) {	%>
		fnConfirmDetail('master', '<%= est_no %>', '');
	<%	}	%>
	});


	function fnConfirmDetail(gubn, est_no, est_seq)
	{
		if (gubn == 'master') {
			$('#est_detail').html('');
			$('#est_detail').load('./estForm.jsp?req_id=<%=req_id%>&est_type=2&est_no='+est_no, '', function() {
				$('#issue_dt').mask('9999.99.99').datepicker();
				$('#travel_start_dt').mask('9999.99.99').datepicker();
				$('#travel_end_dt').mask('9999.99.99').datepicker();
			});
		}
		else if (gubn == 'hotel') {
			cfOpen('/home/voucher/hotelVoucher.jsp?est_no='+est_no+'&est_seq='+est_seq, '조인하와이', 900, 600);
		}
		else if (gubn == 'car') {
			cfOpen('/home/voucher/carVoucher.jsp?est_no='+est_no+'&est_seq='+est_seq, '조인하와이', 900, 600);
		}
		else if (gubn == 'fly') {
			cfOpen('/home/voucher/flyVoucher.jsp?est_no='+est_no+'&est_seq='+est_seq, '조인하와이', 900, 600);
		}
		else if (gubn == 'enjoy') {
			cfOpen('/home/voucher/enjoyVoucher.jsp?est_no='+est_no+'&est_seq='+est_seq, '조인하와이', 900, 600);
		}
	}

	function fnEstPrint(est_no) {
		cfOpen('/home/voucher/masterVoucher.jsp?est_no='+est_no, '조인하와이', 900, 600);
	}

	function fnEstSave(jobType) {

		if (cfCheckNull(document.estSaveForm.title, "제목을 입력해주세요"))	return false;

		if (confirm(MSG_SAVE)) {
			$('#estSaveForm input[name="job_type"]').val(jobType);
			$('#estSaveForm').attr('action', './estSave.do');
			$('#estSaveForm').submit();
		}
	}

	function fnIssue(est_state) {
		if ($('input[name=chk]:checked').length == 0) {
			alert('바우처를 선택하세요');
			return;
		}
		var strMsg = est_state == '3' ? MSG_ISSUE : MSG_ISSUE_CANCEL;
		if (confirm(strMsg)) {
			$('#estListForm').attr('action', './estIssue.do?est_state='+est_state);
			$('#estListForm').submit();
		}
	}


	function fnCheckAll() {
		var chk = $("#chkAll").attr("checked") == "checked" ? true : false;
		$('input:checkbox[name="chk"]').attr("checked", chk);
		$('input[name="est.chk"]').val(chk?"Y":"X");
	}

	</script>
</head>
<body>
<div id="wrap">
	<div id="top">
		<%@ include file="/admin/include/top.jsp" %>
	</div>
	<div id="page">
		<div id="menu">
			<%@ include file="/admin/include/leftMenu.jsp" %>
		</div>
		<div id="contents">
			<div class="menu_title">
				<h1>견적의뢰</h1>
				<p>관리자 > 견적관리 > <b>견적의뢰</b></p>
			</div>
			<div class="clear line_01"></div>



			<ul id="tabs" class="tab_01 mt15">
			    <a href="./reqDetail.jsp<%=where%>&req_id=<%= req_id %>"><li class="off"  code="1"><p>1. <%= "2".equals(list.get("req_gubn",0)) ? "바로예약" : "견적의뢰" %></p></li></a>
			    <a href="./estDetail.jsp<%=where%>&req_id=<%=req_id %>"><li class="off"  code="2"><p>2. 견적서</p></li></a>
			    <li class="on"  code="3"><p>3. 예약확인서</p></li>
			</ul>



			<div id="tabs-2" class=" mt15">


			<form name="estListForm" id="estListForm" method="post">
			<input type="hidden" name="req_id" value="<%=req_id %>"/>
			<input type="hidden" name="est_no" value="<%=est_no %>"/>

				<table width="100%" cellpadding="0" cellspacing="0" class="table_04 mt15">
				<colgroup>
					<col width="30px" />
					<col width="100px" />
					<col  />
					<col width="100px" />
					<col width="100px" />
					<col width="100px" />
					<col width="100px" />
				</colgroup>
				<tr>
					<th><p><input type="checkbox" name="chkAll" id="chkAll" value="Y" onclick="fnCheckAll()"/></p></th>
					<th><p>예약번호</p></th>
					<th><p>제목</p></th>
					<th><p>일정</p></th>
					<th><p>상태</p></th>
					<th><p>작성자</p></th>
					<th><p>최종수정일</p></th>
				</tr>
			<% 	for (int i = 0; i < estList.size(); i++) {	%>
				<tr>
					<td>
						<input type="checkbox" name="chk" value="Y"/>
						<input type="hidden" name="est.chk" value="X"/>
						<input type="hidden" name="est.gubn" value="<%=estList.get("gubn",i) %>"/>
						<input type="hidden" name="est.est_no" value="<%=estList.get("est_no",i) %>"/>
						<input type="hidden" name="est.est_seq" value="<%=estList.get("est_seq",i) %>"/>
					</td>
					<td><%= estList.get("est_no", i) %></td>
					<td class="l">
				<%	if ("guide".equals(estList.get("gubn",i))) { %>
						<a href="/common/file_download.jsp?file_path=<%= estList.get("est_seq", i) %>&file_name=<%= estList.get("title", i) %>"><%= estList.get("title", i) %></a>
				<%	} else { %>
						<a href="#nohref" onclick="fnConfirmDetail('<%= estList.get("gubn", i).trim() %>', '<%= estList.get("est_no", i) %>', '<%= estList.get("est_seq", i) %>')"><%= estList.get("title", i) %></a>
				<%	} %>
					</td>
					<td><%= StringUtil.toDate(estList.get("travel_start_dt", i)) %></td>
					<td><%= estList.get("est_state_name", i) %></td>
					<td><%= estList.get("user_name", i) %></td>
					<td><%= estList.get("up_date", i) %></td>
				</tr>
			<%	} %>
				</table>
			</form>

				<div class="mt20 mb10 c">
					<a href="./reqList.jsp<%=where%>"><img src="/images/admin/btn_list.gif"/></a>
					<a href="#nohref" onclick="fnConfirmDetail('master','','')"><img src="/images/admin/btn_new.gif"  /></a>
					<a href="#nohref" onclick="fnIssue('3')"><img src="/images/admin/btn_issue.gif"  /></a>
					<a href="#nohref" onclick="fnIssue('1')"><img src="/images/admin/btn_issue_cancel.gif"  /></a>
				</div>


				<div id="est_detail" class="mt30">

				</div>

			</div>





		</div>
	</div>
</div>

</body>
</html>
